package cn.bugstack.types.design.framework.tree;

public abstract class AbstractStrategyRouter<T, D, R> implements StrategyMapper<T, D, R>, StrategyHandler<T, D, R> {

    protected StrategyHandler<T, D, R> defaultHandler = StrategyHandler.DEFAULT;

    public R router(T requestParameter, D dynamicContext) throws Exception {
        StrategyHandler<T, D, R> handler = get(requestParameter, dynamicContext);
        if (handler != null) return handler.apply(requestParameter, dynamicContext);
        return defaultHandler.apply(requestParameter, dynamicContext);
    }

}
